<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="true" @searchHandler="searchHandler" :tableObj="tableObj" :show-export-btn='true' export-url='exportUrl2'>
        <f-search-form-item label="区域"  name="areaName"   type="select"    :data="api.custom.areaList"  valueKey="areaName" label-key="areaName" style="width:220px"/>
        <f-search-form-item label="部门" ref="dept"  name="deptId" type="select" :data="api.dept.list"  valueKey="deptId" label-key="deptName" style="width:220px"/>
        <f-search-form-item label="单号" name="orderNo" style="width: 250px"/>
        <f-search-form-item label="发货日期(起)" type="date" name="beginDate" style="width: 250px"/>
        <f-search-form-item label="发货日期(终)" type="date" name="endDate" style="width: 250px"/>
        <f-search-form-item label="供方资信" type="select" slot="advanced" name="supplierBondType" :data="api.busOrder.supplierBondType" style="width: 240px"/>
        <f-search-form-item label="购方资信" type="select" slot="advanced" name="customBondType" :data="api.busOrder.customBondType" style="width: 240px"/>
        <f-search-form-item label="购方" name="customName" slot="advanced" style="width: 220px"/>
        <f-search-form-item label="供方" name="supplierName" slot="advanced" style="width: 220px"/>
        <f-search-form-item label="产品名称" name="drugsName" slot="advanced" style="width: 310px"/>
        <f-search-form-item label="回款日期(起)" type="date" slot="advanced" name="returnDate1" style="width: 250px"/>
        <f-search-form-item label="回款日期(终)" type="date" slot="advanced" name="returnDate2" style="width: 250px"/>
        <f-search-form-item label="返款日期(起)" type="date" slot="advanced" name="refundDate1" style="width: 250px"/>
        <f-search-form-item label="返款日期(终)" type="date" slot="advanced" name="refundDate2" style="width: 250px"/>
        <f-search-form-item label="订单排查" type="select" slot="advanced" name="errorType" :data="api.busOrder.errorType" style="width: 300px"/>
        <a-tooltip title='导出实时数据,请点击该按钮' slot="btn">
        <a-button  style='margin-left: 3px' @click='clearExport' >清理缓存</a-button>
        </a-tooltip>
      </f-search-form>
      <f-table ref="table"  rowKey="orderDetailsId" :showSetting="true"  :tableColumns="columns" :scroll="{x:true}"  :multiple="false" :operator="operator" :params="queryParam" :api="api.bod" handler="orderDetailsReportHandler">
         <span slot="orderNo" slot-scope="text, record, index">
            <span v-clipboard:copy="text" v-clipboard:success="onCopy" style="cursor:pointer">{{text}}</span>
        </span>
        <span slot="saleType" slot-scope="text, record">
        <template>
        <span>
          <a-tag v-if="text==1" color="blue">销售</a-tag>
          <a-tag v-if="text==2" color="blue">退货</a-tag>
          <a-tag v-if="text==3" color="blue">补货</a-tag>
          <a-tag v-if="text==4" color="blue">票折</a-tag>
        </span>
        </template>
      </span>
         <span slot="action" slot-scope="text, record">
          <template>
             <a @click="$refs.orderInfoDrawer.showDrawer(record)" >查看</a>
<!--              <a-divider type="vertical"  v-if="superAdmin"/>-->
<!--             <a @click="initSettle(record)" v-if="superAdmin">初结算</a>-->
          </template>
       </span>
      </f-table>
      <order-info-drawer ref="orderInfoDrawer"></order-info-drawer>
    </a-card>

  </div>
</template>
<script>
  import api from './../../order/js/api'
  import OrderInfoDrawer from '@/views/module/business/order/order_info_drawer'

  export default {
    name: 'TableList',
    components: {
      OrderInfoDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      let customFlag=this.$store.state.user.customFlag
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {
          companyId:this.$store.state.user.companyId
        },
        tableObj:null,
        superAdmin: this.superAdmin,
        // 表头
        columns: [
          {
            title: '#',
            width: '70px',
            align: 'center',
            fixed: 'left',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '操作',
            align: 'center',
            width: '100px',
            dataIndex:'action',
            fixed: 'left',
            scopedSlots: { customRender: 'action' }
          },
          {
            title: '单号',
            align: 'left',
            fixed: 'left',
            width: '130px',
            dataIndex: 'orderNo',
            scopedSlots: { customRender: 'orderNo' }
          },
          {
            title: '类型',
            align: 'left',
            width: '80px',
            dataIndex: 'saleType',
            scopedSlots: { customRender: 'saleType' },
            filters: [
              { text: '销售', value: '1' },
              { text: '退货', value: '2'},
              { text: '票折', value: '4'},
              { text: '补货', value:'3' },
            ]
          },
          {
            title: '垫付状态',
            align: 'left',
            width: '90px',
            dataIndex: 'supplierBondState',
            filters: [
              { text: '无', value: -1 },
              { text: '未支付', value: 0},
              { text: '已支付', value:2 },
              { text: '已退款', value:3 }
            ]
          },
          {
            title: '回款状态',
            align: 'left',
            width: '90px',
            dataIndex: 'customReturnState',
            filters: [
              { text: '未回款', value: 0 },
              { text: '已回款', value:2}
            ]
          },
          {
            title: '厂返状态',
            align: 'left',
            width: '90px',
            dataIndex: 'supplierRefundState',
            filters: [
              { text: '未返款', value: 0 },
              { text: '已开票', value: 1},
              { text: '已返款', value:2 }
            ]
          },
          {
            title: '结算状态',
            align: 'left',
            width: '90px',
            dataIndex: 'settleState',
            filters: [
              { text: '未结算', value: 0 },
              { text: '部分结算', value: 1},
              { text: '已结算', value:2 }
            ]
          },
          {
            title: '资保金状态',
            align: 'left',
            width: '100px',
            dataIndex: 'customBondState',
            filters: [
              { text: '无', value: 0},
              { text: '未退款', value:1 },
              { text: '已退款', value:2 }
            ]
          },
          {
            title: '发(退)货日期',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'saleDate'
          },
          {
            title: '区域',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'areaName'
          },
          {
            title: '部门',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'deptName'
          },
          {
            title: '业务员',
            align: 'left',
            width: '75px',
            sorter: true,
            dataIndex: 'saleManName'
          },
          {
            title: '购货方',
            align: 'left',
            width: '120px',
            ellipsis: true,
            sorter: true,
            dataIndex: 'customName'
          },
          {
            title: '供货方',
            align: 'left',
            sorter: true,
            width: '120px',
            ellipsis: true,
            dataIndex: 'supplierName'
          },
          {
            title: '商品',
            align: 'left',
            sorter: true,
            width: '120px',
            ellipsis: true,
            dataIndex: 'drugsName'
          },
          {
            title: '规格',
            align: 'left',
            width: '70px',
            ellipsis: true,
            dataIndex: 'drugsSpec'
          },
          {
            title: '数量',
            align: 'left',
            width: '70px',
            dataIndex: 'saleNum'
          },
          {
            title: '单价',
            align: 'left',
            width: '70px',
            dataIndex: 'salePrice'
          },
          {
            title: '发(退)货金额',
            align: 'left',
            width: '90px',
            dataIndex: 'saleAmount'
          },
          {
            title: '回款金额',
            align: 'left',
            width: '80px',
            dataIndex: 'returnAmount'
          },
          {
            title: '预付款金额',
            align: 'left',
            width: '80px',
            dataIndex: 'customYsk'
          },
          {
            title: '回款日期',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'returnDate'
          }, {
            title: '公司垫款',
            align: 'left',
            width: '80px',
            dataIndex: 'supplierPayBond'
          }, {
            title: '垫付日期',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'supplierBondPayDate'
          }, {
            title: '资保金应收',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'customBond'
          }, {
            title: '资保金多收',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'overAmount'
          },  {
            title: '资保金实收',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'customBondTake'
          }, {
            title: '收款日期',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'takeDate'
          }, {
            title: '退资保金',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'returnCustomBond'
          }, {
            title: '退款日期',
            align: 'left',
            width: '100px',
            sorter: true,
            dataIndex: 'returnCustomBondDate'
          }, {
            title: '发票日期',
            width: '100px',
            align: 'left',
            dataIndex: 'invoiceDate'
          }, {
            title: '发票号码',
            align: 'left',
            ellipsis: true,
            width: '110px',
            dataIndex: 'invoiceNo'
          }, {
            title: '发票金额',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'invoiceAmount'
          }, {
            title: '成本价',
            align: 'left',
            width: '60px',
            hidden:customFlag,
            dataIndex: 'costPrice'
          }, {
            title: '成本金额',
            align: 'left',
            width: '80px',
            hidden:customFlag,
            isStatistics: true,
            dataIndex: 'costAmount'
          }, {
            title: '供方高开税金',
            align: 'left',
            width: '100px',
            isStatistics: true,
            dataIndex: 'supplierGapUpTaxesAmount'
          }, {
            title: '供方返款费率',
            align: 'left',
            width: '100px',
            dataIndex: 'supplierSettleRate'
          }, {
            title: '供方应返',
            align: 'left',
            isStatistics: true,
            width: '100px',
            dataIndex: 'supplierRetable'
          }, {
            title: '供方实返',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'supplierRefundAmount'
          }, {
            title: '实返日期',
            align: 'left',
            width: '85px',
            dataIndex: 'supplierRefundAmountDate'
          },{
            title: '与供方开票金额',
            align: 'left',
            width: '120px',
            dataIndex: 'invoicePaymentAmount'
          }, {
            title: '开票税金',
            align: 'left',
            isStatistics: true,
            width: '80px',
            dataIndex: 'invoiceSj'
          }, {
            title: '开票日期',
            align: 'left',
            ellipsis: true,
            width: '120px',
            dataIndex: 'invoiceAmountDate'
          },
          {
            title: '开票单号',
            align: 'left',
            width: '100px',
            ellipsis: true,
            dataIndex: 'invoicePaymentNo'
          },
          {
            title: '开票单位',
            align: 'left',
            width: '100px',
            ellipsis: true,
            dataIndex: 'invoiceunitName'
          },
          {
            title: '退垫付款',
            align: 'left',
            width: '80px',
            dataIndex: 'returnSupplierBond'
          },
          {
            title: '退款日期',
            align: 'left',
            width: '100px',
            dataIndex: 'supplierRetBondDate'
          },
          {
            title: '结算高开税金',
            align: 'left',
            isStatistics: true,
            width: '100px',
            dataIndex: 'customSettleGapUpAmount'
          },
          {
            title: '结算发货金额',
            align: 'left',
            isStatistics: true,
            width: '100px',
            dataIndex: 'settleSendAmount'
          },
          {
            title: '结算价',
            align: 'left',
            width: '60px',
            dataIndex: 'settlePrice'
          },
          {
            title: '结算费率',
            align: 'left',
            width: '80px',
            dataIndex: 'customSettleRate'
          },
          {
            title: '应结金额',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'settleAmount'
          },
          {
            title: '已结金额',
            align: 'left',
            width: '80px',
            dataIndex: 'settleRealAmount'
          },
          {
            title: '结算日期',
            align: 'left',
            width: '100px',
            dataIndex: 'settlePayDate'
          },
          {
            title: '支付账户',
            align: 'left',
            width: '120px',
            ellipsis: true,
            dataIndex: 'settlePayBankName'
          },
          {
            title: '应结金额2',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'settleAmount2'
          },
          {
            title: '已结金额',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'settleRealAmount2'
          },
          {
            title: '结算日期',
            align: 'left',
            width: '100px',
            dataIndex: 'settlePayDate2'
          },
          {
            title: '应结金额3',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'settleAmount3'
          },
          {
            title: '已结金额3',
            align: 'left',
            width: '80px',
            isStatistics: true,
            dataIndex: 'settleRealAmount3'
          },
          {
            title: '结算日期',
            align: 'left',
            width: '100px',
            dataIndex: 'settlePayDate3'
          },
          {
            title: '公司利润',
            align: 'left',
            isStatistics: true,
            width: '80px',
            hidden:customFlag,
            dataIndex: 'profitAmount'
          },
          {
            title: '批号',
            align: 'left',
            width: '80px',
            dataIndex: 'drugsLotNo'
          },
          {
            title: '备注',
            align: 'left',
            ellipsis: true,
            width: '120px',
            dataIndex: 'remark'
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    mounted() {
      this.tableObj=this.$refs.table
    },
    methods: {
      onCopy() {
        this.$message.success('复制成功!')
      },
      initSettle(record){
        this.http.confirm(this, {
          content: '确认初始化结算吗?',
          url: api.payment.initSettlePayment,
          data: {
            orderDetailsId: record.orderDetailsId
          }
        })
      },
      clearExport(){
        this.http.post(this, {
          url: this.api.bod.clearExportData
        })
      }
    }
  }
</script>
